// 测试shared_skills表数据查询
const mysql = require('mysql2/promise');
const dotenv = require('dotenv');

// 加载环境变量
dotenv.config();

// 创建数据库连接池
const pool = mysql.createPool({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0
});

// 测试查询shared_skills表
async function testSharedSkills() {
  try {
    console.log('测试连接shared_skills表...');
    const [rows] = await pool.query('SELECT * FROM shared_skills WHERE status = ?', ['approved']);
    console.log(`查询成功，找到 ${rows.length} 条记录:`);
    console.log('第一条记录结构:', rows[0]);
    rows.forEach(row => {
      // 尝试获取可能的标题字段
      const title = row.title || row.skill_name || '无标题';
      console.log(`- ${title} (ID: ${row.skill_id})`);
    });
    return rows;
  } catch (error) {
    console.error('查询失败:', error.message);
    throw error;
  } finally {
    // 关闭连接池
    pool.end();
  }
}

testSharedSkills()
  .then(() => console.log('测试完成'))
  .catch(() => console.log('测试失败'));